<template>
	<view class="container">
		<view v-if="showCashPanel">
			<view class="user-section">
				<view class="vip-card-box" style="background-image: url(/static/images/card_bg.png);background-size: 100% 100%;">
					<view class="text-white text-xxlx text-center padding-top-lg margin-top-lg">{{ usercoin }}</view>
					<view class="text-white text-lg text-center padding-top-sm">可用余额(元)</view>
				</view>
			</view>
			<view class="cu-form-group margin-lr-lg border-b-line padding-0">
				<view class="title">转账金额</view>
			</view>
			<view class="cu-form-group margin-lr-lg border-b-line padding-0">
				<text class="text-price text-xxlx"></text>
				<input class="text-xxlx" data-key="coin" number focus placeholder="0.00" v-model="coin" @input="inputCoin">
			</view>
		<view class="cu-form-group margin-lr-lg border-b-line padding-0">
			<view class="title">对方账号</view>
		</view>
		<view class="cu-form-group margin-lr-lg border-b-line padding-0">
			<input focus placeholder="请填写收款人账号" v-model="zhanghao" />
		</view>
		<view class="cu-form-group margin-lr-lg border-b-line padding-0">
			<view class="title">对方真实姓名</view>
		</view>
		<view class="cu-form-group margin-lr-lg border-b-line padding-0">
			<input focus placeholder="请填写收款人姓名" v-model="name" />
		</view>	
			<view class="cu-form-group margin-lr-lg padding-0 submit_btn">
				<button :disabled="enableTransfer" class="cu-btn" type="button" @click="cashOut()">确认转账</button>
			</view>
		</view>
		<view :class="[modalName == 'showPayPwd' ? 'cu-modal show' : 'cu-modal']">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="content">支付密码</view>
					<view class="action">
						<text class="cuIcon-close text-red" @click="hideModal()"></text>
					</view>
				</view>
				<view class="padding-xl">
					<view>
						<view class="flex-box padding-bottom-sm text-sm"></view>
						<validcode ref="validcode" :maxlength="6" :isPwd="true" @finish="finish"></validcode>
					</view>
				</view>
			</view>
		</view>
	<view class="footer-info">
	    <view>1. 最小转账金额{{this.mintransfer}}元</view>
	    <view>2. 转账功能达到VIP2以上自动开通，VIP2以下不支持使用本功能</view>
<!-- 	    <view>3. 最低提现金额为 {{this.mincash}}元，最高提现金额为 {{this.maxcash}}元</view>
	    <view>4. 提现受理时间为 {{this.allowable[0]}}:00-{{this.allowable[1]}}:00</view> -->
	</view>	
	</view>

</template>
<script>
	import validcode from "@/components/validCode/validCode.vue";
	export default {
		components: {
			validcode
		},
		data() {
			return {
				loaded: !1,
				loading: !1,
				modalName: null,
				enableScroll: !0,
				loadMoreStatus: 2,
				showLoadMoreStatus: !1,
				coin: "",
				usercoin: "0.00",
				mintransfer: "1",
				maxcash: "1",
				allowable:null,
				casetimes: "1",
				enableTransfer: !0,
				showCashPanel: !1,
				passInputTips: "",
				bankData: {},
				bank_id:'0',
				zhanghao:"",
				name:""
			}
		},

		onLoad: function (option) {
			this.helper.checkLogin();
			this.loadData();
		},
		onShow:function(e){
			let pages = getCurrentPages();
			let currPage = pages[pages.length-1];
			if (currPage.$vm.bank_id){
				this.bank_id = currPage.$vm.bank_id;
				//this.loadData();
			}
		},
		methods: {
			loadData:function(){
				//获取基础参数
				// uni.showLoading({
				// 	title:"数据加载中",
				// 	mask:true
				// })
				var info = uni.getStorageSync("userinfo");
				let timestamp = this.helper.now();
				let sign = this.helper.setSign(['bank_id='+this.bank_id,'token='+info.token,'timestamp='+timestamp]);
				this.helper.req({
					api:"transferBefore",
					timestamp:timestamp,
					data:{bank_id:this.bank_id,token:info.token},
					header:{sign:sign},
					method:'GET',
				}).then(res=>{
					uni.hideLoading();
					switch (res.data.data.status){
						case 'noauth':
							uni.showModal({
								title: "提示",
								content: '帐户未实名，现在实名？',
								showCancel:false,
								confirmText: "现在实名",
								success:function(res){
									if(res.confirm){
										uni.navigateTo({
											url: "/pages/user/certification"
										})
									}
								}
							})
							break;
						case 'nopaypwd':
							uni.showModal({
								title: "提示",
								content: '未设置支付密码',
								showCancel:false,
								confirmText: "现在设置",
								success:function(res){
									if(res.confirm){
										uni.navigateTo({
											url: "/pages/user/repasswd?type=pay"
										})
									}
								}
							})
							break;
						case "success":
							this.level = res.data.data.level,
							this.usercoin = res.data.data.balance,
							this.mintransfer = res.data.data.mintransfer,
							this.maxcash = res.data.data.maxcash,
							this.canlevel = res.data.data.canlevel,
							this.showCashPanel = !0,
							this.loaded = !0;
							break;
						default:
						
							break;
					}
				})
			},
			inputCoin: function(e) {
				this.enableTransfer = !(parseFloat(e.detail.value) > 0);
			},
			cashOut: function() {
				this.$refs.validcode.clear();
				this.passInputTips = "金额：" + this.coin;
				this.enableTransfer = !0;
				this.modalName = "showPayPwd";
			},
			navToBank: function() {
				uni.navigateTo({
					url: "/pages/bank/index?source=1"
				})
			},
			finish: function(e) {
				this.modalName = null;
				if(e.length < 6){
					uni.showToast({
						title:"密码无效",
						icon:"none"
					})
					this.enableTransfer = !1
					return;
				}
				if(this.coin == '' || parseFloat(this.coin) <= 0){
					uni.showToast({
						title:"请输入转出金额",
						icon:"none"
					})
					this.enableTransfer = !1
					return;
				}
				if(this.canlevel > this.level){
					uni.showToast({
						title:"您的会员等级还不能使用转账功能",
						icon:"none",
						duration: 5000 // 设置消息显示的时间为 5000 毫秒
					})
					this.enableTransfer = !1
					return;
				}				
				if(parseFloat(this.coin) < this.mincash){
					uni.showToast({
						title:"转账金额不能小于" + this.mincash,
						icon:"none"
					})
					this.enableTransfer = !1
					return;
				}
				// if(parseFloat(this.coin) > this.maxcash){
				// 	uni.showToast({
				// 		title:"当前会员等级最高单笔提现额度为" + this.maxcash+"元",
				// 		icon:"none",
				// 		duration: 5000 // 设置消息显示的时间为 2000 毫秒
				// 	})
				// 	this.enableTransfer = !1
				// 	return;
				// }
				this.enableTransfer = !0;
				var info = uni.getStorageSync("userinfo");
				let timestamp = this.helper.now();
				let sign = this.helper.setSign(['pwd='+e,'zhanghao='+this.zhanghao,'name='+this.name,'coin='+this.coin,'timestamp='+timestamp,'token='+info.token]);
				this.helper.req({
					api:"doTransfer",
					timestamp:timestamp,
					data:{pwd:e,zhanghao: this.zhanghao,name:this.name,coin:this.coin,token:info.token},
					header:{sign:sign},
					method:'POST',
				}).then(res=>{
					uni.showModal({
						title: "提示",
						content: '转账提交成功，等待系统审核！',
						showCancel:false,
						confirmText: "确认",
						success:function(res){
							if(res.confirm){
								uni.navigateTo({
									url: "/pages/wallet/transfer"
								})
							}
						}
					})
				})
				this.coin = "";
			},
			hideModal: function() {
				this.modalName = null,
				this.enableTransfer = !1
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #fff;
	}
	.vip-card-box {
		height: 260upx;
		border-radius: 16upx;
		overflow: hidden;
		position: relative;
		padding: 0 20upx 24upx;
		margin: 0 20upx 0;
		line-height: 50upx;
		z-index: 10
	}
	input.text-xxlx{
		font-size: 50upx;
	}
	.cu-list.menu-avatar > .cu-item > .cu-avatar{
		border: 2upx solid #eee;
	}
	.footer-info {
	    margin: 20upx;
	    font-size: 28upx;
	    color: #666;
	    line-height: 1.5;
	}
</style>